From bf891c9366a86cc06831ab70a7a85ce5673b71e1 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Fri, 12 May 2017 04:28:11 +1000 Subject: Refactor T-Flash implementation before merging. --- heimdall/source/EnableTFlashPacket.h | 39 ++++++++++++++++++++++ heimdall/source/FlashAction.cpp | 31 +++++++++-------- heimdall/source/SessionSetupPacket.h | 3 +- heimdall/source/TFlashModePacket.h | 65 ------------------------------------ heimdall/source/TFlashModeResponse.h | 58 -------------------------------- 5 files changed, 56 insertions(+), 140 deletions(-) create mode 100644 heimdall/source/EnableTFlashPacket.h delete mode 100644 heimdall/source/TFlashModePacket.h delete mode 100644 heimdall/source/TFlashModeResponse.h diff --git a/heimdall/source/EnableTFlashPacket.h b/heimdall/source/EnableTFlashPacket.h new file mode 100644 index 0000000..7b22ebd --- /dev/null +++ b/heimdall/source/EnableTFlashPacket.h @@ -0,0 +1,39 @@ +/* Copyright (c) 2010-2017 Benjamin Dobell, Glass Echidna + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE.*/ + +#ifndef ENABLETFLASHPACKET_H +#define ENABLETFLASHPACKET_H + +// Heimdall +#include "SessionSetupPacket.h" + +namespace Heimdall +{ + class EnableTFlashPacket : public SessionSetupPacket + { + public: + + EnableTFlashPacket() : SessionSetupPacket(SessionSetupPacket::kEnableTFlash) + { + } + }; +} + +#endif diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index a3ab85b..b0f19e0 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -24,14 +24,13 @@ // Heimdall #include "Arguments.h" #include "BridgeManager.h" +#include "EnableTFlashPacket.h" #include "EndModemFileTransferPacket.h" #include "EndPhoneFileTransferPacket.h" #include "FlashAction.h" #include "Heimdall.h" #include "Interface.h" #include "SessionSetupResponse.h" -#include "TFlashModePacket.h" -#include "TFlashModeResponse.h" #include "TotalBytesPacket.h" #include "Utility.h" @@ -383,34 +382,34 @@ static PitData *getPitData(BridgeManager *bridgeManager, FILE *pitFile, bool rep return (pitData); } -static bool setTFlashMode(BridgeManager *bridgeManager) +static bool enableTFlash(BridgeManager *bridgeManager) { bool success; - TFlashModePacket *tFlashModePacket = new TFlashModePacket(); - success = bridgeManager->SendPacket(tFlashModePacket); - delete tFlashModePacket; + EnableTFlashPacket *enableTFlashPacket = new EnableTFlashPacket(); + success = bridgeManager->SendPacket(enableTFlashPacket); + delete enableTFlashPacket; if (!success) { - Interface::PrintError("Failed to request T-Flash mode!\n"); + Interface::PrintError("Failed to send T-Flash packet!\n"); return false; } - TFlashModeResponse *tFlashModeResponse = new TFlashModeResponse(); - success = bridgeManager->ReceivePacket(tFlashModeResponse, 5000); - unsigned int result = tFlashModeResponse->GetResult(); - delete tFlashModeResponse; + SessionSetupResponse *enableTFlashResponse = new SessionSetupResponse(); + success = bridgeManager->ReceivePacket(enableTFlashResponse, 5000); + unsigned int result = enableTFlashResponse->GetResult(); + delete enableTFlashResponse; if (!success) { - Interface::PrintError("Failed to receive T-Flash mode result!\n"); + Interface::PrintError("Failed to receive T-Flash response!\n"); return false; } - if(result) + if (result) { - Interface::PrintError("Failed to set T-Flash mode (received: %d)!\n", result); + Interface::PrintError("Unexpected T-Flash response!\nExpected: 0\nReceived: %d\n", result); return false; } @@ -459,7 +458,7 @@ int FlashAction::Execute(int argc, char **argv) bool reboot = arguments.GetArgument("no-reboot") == nullptr; bool resume = arguments.GetArgument("resume") != nullptr; bool verbose = arguments.GetArgument("verbose") != nullptr; - bool tflash_mode = arguments.GetArgument("tflash") != nullptr; + bool tflash = arguments.GetArgument("tflash") != nullptr; if (arguments.GetArgument("stdout-errors") != nullptr) Interface::SetStdoutErrors(true); @@ -546,7 +545,7 @@ int FlashAction::Execute(int argc, char **argv) return (1); } - if (tflash_mode && !setTFlashMode(bridgeManager)) + if (tflash && !enableTFlash(bridgeManager)) { closeFiles(partitionFiles, pitFile); delete bridgeManager; diff --git a/heimdall/source/SessionSetupPacket.h b/heimdall/source/SessionSetupPacket.h index 055e701..0d7cf75 100644 --- a/heimdall/source/SessionSetupPacket.h +++ b/heimdall/source/SessionSetupPacket.h @@ -36,7 +36,8 @@ namespace Heimdall kDeviceType = 1, // ? kTotalBytes = 2, //kEnableSomeSortOfFlag = 3, - kFilePartSize = 5 + kFilePartSize = 5, + kEnableTFlash = 8 }; private: diff --git a/heimdall/source/TFlashModePacket.h b/heimdall/source/TFlashModePacket.h deleted file mode 100644 index 4d5bc07..0000000 --- a/heimdall/source/TFlashModePacket.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE.*/ - -#ifndef TFLASHMODEPACKET_H -#define TFLASHMODEPACKET_H - -// Heimdall -#include "ControlPacket.h" - -namespace Heimdall -{ - class TFlashModePacket : public ControlPacket - { - public: - - enum - { - kRequestTFlashMode = 0x08 - }; - - protected: - - enum - { - kDataSize = ControlPacket::kDataSize + 4 - }; - - private: - - unsigned int subcmd = TFlashModePacket::kRequestTFlashMode; - - public: - - TFlashModePacket(void) : ControlPacket(ControlPacket::kControlTypeSession) - { - - } - - virtual void Pack(void) - { - ControlPacket::Pack(); - - PackInteger(ControlPacket::kDataSize, subcmd); - } - }; -} - -#endif diff --git a/heimdall/source/TFlashModeResponse.h b/heimdall/source/TFlashModeResponse.h deleted file mode 100644 index a9a3558..0000000 --- a/heimdall/source/TFlashModeResponse.h +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE.*/ - -#ifndef TFLASHMODERESPONSE_H -#define TFLASHMODERESPONSE_H - -// Heimdall -#include "ResponsePacket.h" - -namespace Heimdall -{ - class TFlashModeResponse : public ResponsePacket - { - private: - - unsigned int result; - - public: - - TFlashModeResponse() : ResponsePacket(ResponsePacket::kResponseTypeSessionSetup) - { - } - - unsigned int GetResult(void) const - { - return (result); - } - - bool Unpack(void) - { - if (!ResponsePacket::Unpack()) - return (false); - - result = UnpackInteger(ResponsePacket::kDataSize); - - return (true); - } - }; -} - -#endif -- cgit v1.2.3